#include <57header.h>

// 客户端
int main(int argc,char*argv[])
{
    char *port = "8080";
    char *ip = "192.168.106.129";

    int socket_fd = socket(AF_INET, SOCK_STREAM, 0);


    struct sockaddr_in sockaddr;
    sockaddr.sin_family = AF_INET;
    sockaddr.sin_port = htons(atoi(port));
    sockaddr.sin_addr.s_addr = inet_addr(ip);
    
    int ret = connect(socket_fd,(struct sockaddr *)&sockaddr, sizeof(sockaddr));
    ERROR_CHECK(ret, -1, "connect");

    while(1){
        // 读取标准输入
        char buf[60] = {0};
        read(STDIN_FILENO, buf, sizeof(buf));
        send(socket_fd, buf, sizeof(buf), 0);

        // 读取网络数据
        bzero(buf, sizeof(buf));
        recv(socket_fd,buf, sizeof(buf), 0);
        printf("serve: %s \n", buf);
    }

    close(socket_fd);
    return 0;
}

